package com.nhjf.dao.teachers;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.teachers.CoursesCollection;
import com.nhjf.pojo.qo.teachers.CoursesCollectionQo;

@Repository
public class CoursesCollectionDao extends BaseDao<CoursesCollection, CoursesCollectionQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, CoursesCollectionQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("coursesId", qo.isSeachCourses()?FetchMode.JOIN:FetchMode.SELECT);	
			criteria.setFetchMode("userId", qo.isSeachUser()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getUserId()!=null) {
				criteria.add(Restrictions.eq("userId.id",qo.getUserId()));
			}
			if(qo.getCoursesId()!=null) {
				criteria.add(Restrictions.eq("coursesId.id",qo.getCoursesId()));
			}
			if(qo.getCollectionUserType()!=null) {
				criteria.add(Restrictions.eq("collectionUserType",qo.getCollectionUserType()));
			}
			if(qo.getCoursesCollectionId()!=null) {
				criteria.add(Restrictions.eq("id",qo.getCoursesCollectionId()));
			}
			
		}
		return criteria;
	}

	@Override
	protected Class<CoursesCollection> getEntityClass() {
		// TODO Auto-generated method stub
		return CoursesCollection.class;
	}
	
}
